package hemowork_8_29;

import java.io.*;
import java.util.Scanner;

public class Test01 {
    public static void main(String[] args) throws IOException {
        //要求用户顺序输入以上四个信息
        System.out.println("请依次输入：name，pwd，nick，age ");
        Scanner scan = new Scanner(System.in);
        String path = "src/main/java/hemowork_8_29/";
        User user = new User();
        for (int i = 0; i < 4; i++) {
            switch (i) {
                case 0:
                    System.out.print("请输入您的名字：");
                    user.setName(scan.nextLine());
                    break;
                case 1:
                    System.out.print("密码：");
                    user.setPwd(scan.nextLine());
                    break;
                case 2:
                    System.out.print("nick：");
                    user.setNick(scan.nextLine());
                    break;
                default:
                    System.out.print("年龄：");
                    try {
                        user.setAge(Integer.parseInt(scan.nextLine()));
                        System.out.println("感谢您的使用，信息录入完毕。");
                    } catch (NumberFormatException e) {
                        System.out.println("您的输入有误，请重新输入(数字)：");
                        i = 2;
                    }
                    break;
            }
        }
        System.out.println(user);
        //实例化
        FileOutputStream fos = new FileOutputStream(
                path+user.getName() + ".obj");
        ObjectOutputStream oos = new ObjectOutputStream(fos);

        oos.writeObject(user);

        System.out.println("写入完毕！！！");
        oos.close();

    }
}
